/**
 * 
 */
package switchviz;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.apache.log4j.Logger;
import switchviz.gui.MainFrame;
import switchviz.util.Log4jSupport;


/**
 * @author Thomas
 *
 */
public class Application
{
	private static Logger logger = Logger.getLogger(Application.class);
	private static Application _instance = null;
	private static final String VERSION = "1.9";
	private MainFrame _mainFrame = null;

	/**
	 * Entry-point of application
	 */
	public static void main(String[] args)
	{
		Log4jSupport.initialize();
		
		setLookAndFeel();
		
		SwingUtilities.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					Application.getInstance();
				}
				catch (Exception exception)
				{
					//exception.printStackTrace();
					logger.fatal("Final exception handler!", exception);
				}
			}
		});
	}

	private static void setLookAndFeel()
	{
		try 
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} 
		catch (Exception e) 
	    {
			logger.error(e);
			e.printStackTrace();
	    }
	}
	
	private Application()
	{
		super();
		
		initialize();
	}
	
	public static Application getInstance()
	{
		if (_instance == null)
			_instance = new Application();
		
		return _instance;
	}
	
	public MainFrame getMainFrame()
	{
		if (_mainFrame == null)
			_mainFrame = new MainFrame();
		
		return _mainFrame;
	}
	
	public static String getVersion()
	{
		return VERSION;
	}
	
	private void initialize()
	{
		getMainFrame().setVisible(true);
		
		logger.info("Initialized ...");
	}
}
